package com.ygp.dtp.core.reject;

import com.ygp.dtp.core.thread.DynamicThreadPoolExecutor;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @description: 拒绝策略的数量处理类
 * @motto: 代码源于生活，高于生活艺术
 * @author: zhouhengzhe
 * @date: 2022/8/8 10:30
 * @since 1.0
 **/
public interface RejectedCountableHandler extends RejectedExecutionHandler {

    /**
     * 类型
     *
     * @return 返回拒绝策略类型
     */
    String type();

    /**
     * 做一些拒绝策略之前的事情
     *
     * @param executor 线程池
     */
    default void beforeReject(ThreadPoolExecutor executor) {
        if (executor instanceof DynamicThreadPoolExecutor) {
            DynamicThreadPoolExecutor dynamicThreadPoolExecutor = (DynamicThreadPoolExecutor) executor;
            dynamicThreadPoolExecutor.incRejectCount(1);
//            AlarmManager.triggerAlarm(() > AlarmManager.Alarm(dynamicThreadPoolExecutor, NotifyTypeEnum.REJECT));
        }
    }
}
